﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.IO;
using System.Windows.Threading;
using System.Threading;
using System.Windows.Media.Animation;

namespace SignatureSystem
{
	/// <summary>
	/// UC_SignPanel.xaml 的交互逻辑
	/// </summary>
	public partial class UC_SignPanel : UserControl
	{
        private const string m_SaveImageToDiskPathName = "\\Resources\\Signature\\";
		public UC_SignPanel()
		{
			this.InitializeComponent();
		}

		private void SurfaceButton_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			if (inkCanvas.IsHitTestVisible)
            {
                inkCanvas.IsHitTestVisible = false;
            }
            else
            {
                inkCanvas.IsHitTestVisible = true;
            }
		}
		
		private void SurfaceButton1_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			inkCanvas.Strokes.Clear();
		}
		
		private void SurfaceButton2_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			inkCanvas.IsHitTestVisible = false;
			controlPanel.Visibility = System.Windows.Visibility.Collapsed;
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate()
            {
                ImageProcessHelper.SaveCanvasToJpeg(LayoutRoot, GenerateSaveFolder());
            });
		}

        private string GenerateSaveFolder()
        {
            string m_SaveTargetFolder = Directory.GetCurrentDirectory() + m_SaveImageToDiskPathName;
            if (!Directory.Exists(m_SaveTargetFolder))
            {
                Directory.CreateDirectory(m_SaveTargetFolder);
            }
            m_SaveTargetFolder += DateTime.Now.ToString("yyMMdd");
            if (!Directory.Exists(m_SaveTargetFolder))
            {
                Directory.CreateDirectory(m_SaveTargetFolder);
            }
            m_SaveTargetFolder += "/" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".jpg";

            return m_SaveTargetFolder;
        }
	}
}